package com.briup.day17;

import java.io.*;

/**
 * 字符输入流 和字符输出流
 * @author lining
 * @date 2024/1/29 14:44
 */
public class TestBufferdReaderAndWriter {
    public static void main(String[] args) throws Exception{
        //1.声明流（缓存流）
        BufferedReader br = null;// FileReader
        BufferedWriter bw = null;
        //2.进行赋值
        br = new BufferedReader(new FileReader("a.txt"));
        bw = new BufferedWriter(new FileWriter("b.txt"));
        //3.操作流(读 写 一行数据 )
        String line = null;
        //readLine读到流的末尾提示返回null
        while ((line = br.readLine()) != null){
            //写一行操作
            bw.write(line);

            if(br.ready()){//当字符输入缓存流没有到文件末尾，返回true 达到文件末尾 返回false
//                bw.write("\n");  //直接输出换行符
                bw.newLine();//实现换行 write(行分隔符)
            }else {
                //不添加换行符
            }
        }
        //4.刷新流
        bw.flush();
        //4.关闭流
        br.close();
        bw.close();
    }
}
